package com.atguigu.yygh.hosp.controller;

import com.atguigu.yygh.common.R;
import com.atguigu.yygh.hosp.service.DepartmentService;
import com.atguigu.yygh.hosp.service.HospitalService;
import com.atguigu.yygh.hosp.service.ScheduleService;
import com.atguigu.yygh.model.hosp.Department;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.model.hosp.Schedule;
import com.atguigu.yygh.vo.hosp.DepartmentVo;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import com.atguigu.yygh.vo.hosp.ScheduleOrderVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javafx.concurrent.Worker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Author zhmwi
 * @Date 2021/7/14
 * @Dersciption
 */
@Api("医院展示接口")
@RestController
@RequestMapping("/api/hosp/hospital")
public class HospitalApiController {

    @Autowired
    private HospitalService hospitalService;
    @Autowired
    private DepartmentService departmentService;

    @Autowired
    private ScheduleService scheduleService;
    //带分页带条件查询医院
    @ApiOperation("带分页带条件查询医院")
    @GetMapping("/getHospitalByPageAndCondition/{page}/{limit}")
    public R getHospitalByPageAndCondition(@PathVariable("page") Integer page,
                         @PathVariable("limit") Integer limit,
                         HospitalQueryVo hospitalQueryVo){
        Page<Hospital> pageModel =hospitalService.getHospitalByPageAndCondition(page,limit,hospitalQueryVo);
        return R.ok().data("pageModel",pageModel);
    }
    //模糊查询医院
    @ApiOperation("模糊查询医院")
    @GetMapping("/getHospitalByFuzzy/{hosname}")
    public R getHospitalByFuzzy(@PathVariable("hosname") String hosname){
        List<Hospital> hospitalList = hospitalService.getHospitalByFuzzy(hosname);
        return R.ok().data("hospitalList",hospitalList);
    }
    //根据医院编码查询医院详情 医院基本信息 预约信息
    @ApiOperation("根据医院编码查询医院详情")
    @GetMapping("getHospitalInfoByHoscode/{hoscode}")
    public R getHospitalInfoByHoscode(@PathVariable("hoscode") String hoscode){

        Map<String,Object> map = hospitalService.getHospitalInfoByHoscode(hoscode);
        return R.ok().data(map);
    }
    //查询所有科室信息
    @ApiOperation("查询所有科室信息")
    @GetMapping("/department/getDepartmentList/{hoscode}")
    public R getDepartmentList(@PathVariable("hoscode") String hoscode){
        List<DepartmentVo> departmentList = departmentService.getDepartmentList(hoscode);
        return R.ok().data("departmentList",departmentList);
    }
    //查询可预约排班数据
    @ApiOperation("查询可预约排班数据")
    @GetMapping("auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public R getBookingSchedule(@PathVariable Integer page,
                                @PathVariable Integer limit,
                                @PathVariable String hoscode,
                                @PathVariable String depcode){
        Map<String,Object> map = hospitalService.getBookingScheduleRule(page,limit,hoscode,depcode);
        return R.ok().data(map);
    }
    //查询当前日期的排班记录
    @ApiOperation("查询排班数据")
    @GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public R findScheduleList(@PathVariable String hoscode,
                              @PathVariable String depcode,
                              @PathVariable String workDate){
        List<Schedule> scheduleList = scheduleService.getDetailSchedule(hoscode, depcode, workDate);
        return R.ok().data("scheduleList",scheduleList);
    }
    @ApiOperation("根据id获取排班详情")
    @GetMapping("getSchedule/{id}")
    public R getScheduleById(@PathVariable String id){
        Schedule schedule = scheduleService.getScheduleById(id);
        return R.ok().data("schedule",schedule);
    }

    //下单 -- 获取排班详情
    @ApiOperation("根据排班id获取预约下单数据 即 回显下单详情")
    @GetMapping("inner/getScheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(@PathVariable("scheduleId") String scheduleId){
        ScheduleOrderVo scheduleOrderVo = scheduleService.getScheduleOrderVo(scheduleId);
        return scheduleOrderVo;
    }

}
